package com.squapsource.project_euler;

public class Problem1 {

	public static void main(String[] args) {
		long sum = sumMultiplesFormulaic(3, 1000) + sumMultiplesFormulaic(5, 1000)
				- sumMultiplesFormulaic(15, 1000);
		System.out.println("sum: " + sum);
	}

//	private static long sumMultiples(long factor, long maxNumber) {
//		long sum = 0;
//		for (long i = factor; i < maxNumber; i += factor) {
//			sum += i;
//		}
//		return sum;
//	}
	
	private static long sumMultiplesFormulaic(long factor, long maxNumber) {
		long p = (maxNumber-1) / factor;
		return factor*(p*(p+1)) /2;
	}

}
